< previous page page_591 next page >

Page 591
All the values you need to compute A, B, and C are constants determined by the particular sphere and line. When you plug in the values for A, B, and C, you get one of three possible results. First, if B2 4 * A * C < 0, the square root has no real solutions. In this case, the ray does not intersect the sphere in real, three-dimensional space.
Second, if B2 4 * A * C = 0, the equation has a single solution B/2/A. In this case, the ray is tangent to the sphere, meeting it at a single point.
Finally, if B2 4 * A * C > 0, the equation gives two possible values for t. Values less than zero represent points behind the point at which the ray originates. Larger values for t represent points further from the beginning of the ray than the points represented by smaller values. Thus the position on the sphere closest to the point (px, py, pz) in the direction of the vector <vx, vy, vz> corresponds to the smaller positive value of t.
Once you have found the correct value for t, you can plug it into the parametric equations for the line to determine the exact point of intersection.
The following code shows the FindT function for the RaySphere class. The RaySphere class implements the RayTraceable class and FindT is defined by RayTraceable, so the RaySphere class declares this function as RayTraceable_FindT.
e10a6a0a59f035e870d90cca05b85fce.gif
' Return the value T for the point of intersection
' between the vector from point (px, py, pz) in
' the direction <vx, vy, vz>.
'
' direct_calculation is true if we are finding the
' intersection from a viewing position ray. It is
' false if we are finding a reflected intersection
' or a shadow feeler.
Public Function RayTraceable_FindT( _
    ByVal direct_calculation As Boolean, _
    ByVal px As Single, ByVal py As Single, _
    ByVal pz As Single, ByVal Vx As Single, -
    ByVal Vy As Single, ByVal Vz As Single) As Single
Dim A As Single
Dim B As Single
Dim C As Single
Dim Cx As Single
Dim Cy As Single
Dim Cz As Single
Dim B24AC As Single
Dim T1 As Single
Dim T2 As Single
Dim dx As Single
Dim dy As Single
Dim dz As Single

    Cx = Center.Trans(1)
    Cy = Center.Trans(2)
    Cz = Center.Trans(3)

    ' Get the coefficients for the quadratic.

 
< previous page page_591 next page >